//
//  ChildPlanDetailTableViewCell.m
//  FitTime
//
//  Created by dllo on 16/4/6.
//  Copyright © 2016年 赵建平. All rights reserved.
//

#import "ChildPlanDetailTableViewCell.h"

@implementation ChildPlanDetailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.rightImageView = [UIImageView new];
        [self.contentView addSubview:self.rightImageView];
        
        self.titleLable = [UILabel new];
        [self.contentView addSubview:self.titleLable];
        
        self.difficultLable = [UILabel new];
        [self.contentView addSubview:self.difficultLable];
        
        self.waterView = [UIView new];
        [self.contentView addSubview:self.waterView];
        
        self.toolLable = [UILabel new];
        [self.contentView addSubview:self.toolLable];
        
        self.bodyNameLable = [UILabel new];
        [self.contentView addSubview:self.bodyNameLable];
        
        self.timeLable = [UILabel new];
        [self.contentView addSubview:self.timeLable];
        
    }
    return self;
}

-(void)layoutSubviews {
    [super layoutSubviews];
    //图片坐标
    [self.rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView.mas_top).offset(20);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-20);
        make.width.equalTo(@125);
    }];
    //标题坐标
    [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(20);
        make.left.equalTo(self.contentView.mas_top).offset(20);
        make.width.equalTo(@170);
        make.height.equalTo(@30);
        
    }];
    //难度坐标
    [self.difficultLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLable.mas_bottom).offset(3);
        make.left.equalTo(self.contentView.mas_left).offset(20);
        make.height.equalTo(@22.5);
    }];
    self.difficultLable.text = @"难度";
    //水滴坐标
    [self.waterView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLable.mas_bottom).offset(3);
        make.left.equalTo(self.difficultLable.mas_right).offset(5);
        make.size.mas_equalTo(CGSizeMake(45, 22.5));
    }];
    
    
    //工具坐标
    [self.toolLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLable.mas_bottom).offset(3);
        make.left.equalTo(self.waterView.mas_right).offset(15);
        make.height.equalTo(@22.5);
    }];
    //身体部位坐标
    [self.bodyNameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.difficultLable.mas_bottom).offset(3);
        make.left.equalTo(self.contentView.mas_left).offset(20);
        make.width.equalTo(@170);
        make.height.equalTo(@22.5);
        
    }];
    //时间坐标
    [self.timeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bodyNameLable.mas_bottom).offset(3);
        make.left.equalTo(self.contentView.mas_left).offset(20);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-20);
        make.width.equalTo(@170);
    }];
    
    self.timeLable.font = [UIFont systemFontOfSize:12];
    self.titleLable.font = [UIFont systemFontOfSize:17];
    self.bodyNameLable.font = [UIFont systemFontOfSize:12];
    self.difficultLable.font = [UIFont systemFontOfSize:12];
    self.toolLable.font = [UIFont systemFontOfSize:12];
    
    
    
    //    self.rightImageView.backgroundColor = [UIColor redColor];
    //    self.titleLable.backgroundColor = [UIColor greenColor];
    //    self.toolLable.backgroundColor = [UIColor yellowColor];
    //    self.bodyNameLable.backgroundColor = [UIColor orangeColor];
    //    self.timeLable.backgroundColor = [UIColor blueColor];
}

- (void)setSingleModel:(SingleModel *)singleModel {
    _singleModel = singleModel;
    //照片
    NSString *photoString = [NSString stringWithFormat:@"http://ft-video.fit-time.cn/%@.png@!medium", singleModel.ID];
    [self.rightImageView sd_setImageWithURL:[NSURL URLWithString:photoString]];
    //标题
    self.titleLable.text = singleModel.title;
    //水滴
    for (int i = 0; i < singleModel.difficulty; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake( 20 * i, 2, 15, 15)];
        imageView.image = [UIImage imageNamed:@"water_b"];
        [self.waterView addSubview:imageView];
    }
    for (int i = (int)singleModel.difficulty; i < 3 ; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake( 20 * i, 2, 15, 15)];
        imageView.image = [UIImage imageNamed:@"water_w"];
        [self.waterView addSubview:imageView];
    }
    
    //器械
    if (singleModel.instrument.length == 0) {
        self.toolLable.text = @"/无器械";
    } else {
        self.toolLable.text = [NSString stringWithFormat:@"/%@", singleModel.instrument];
    }
    //身体部位
    self.bodyNameLable.text = singleModel.part;
    //时间
    NSString *string = [NSString stringWithFormat:@"%.2ld:%.2ld", (long)singleModel.time / 60,(long)singleModel.time % 60];
    NSString *personString = [NSString stringWithFormat:@"%ld", (long)singleModel.playCount];
    //时间坐标
    self.timeLable.text = [NSString stringWithFormat:@"%@   %@人练过",string, personString];
    
}


@end
